package com.hospital.service.impl;

import com.hospital.dao.JobDao;
import com.hospital.entity.Job;
import com.hospital.service.intf.JobService;
import com.hospital.util.StringUtil;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JobServiceImpl implements JobService {

    @Autowired
    private JobDao jobDao;

    @Override
    public R add(Job job) {
        if(jobDao.add(job) > 0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R delete(Integer id) {
        if(jobDao.delete(id) > 0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R update(Job job) {
        if(jobDao.update(job) > 0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R select() {
        if(jobDao.select() != null){
            return R.ok(jobDao.select());
        }
        return R.fail();
    }

    @Override
    public PageBean selectPage(String job_name, int page, int limit) {
        int start = (page - 1) * limit;

        if(StringUtil.isNotEmpty(job_name)){
            job_name = "%"+job_name+"%";
        }

        return PageBean.ok(jobDao.count(job_name),jobDao.selectPage(job_name,start,limit));
    }
}
